<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="../taglibs.jsp" %>
 <%@taglib prefix="staticResource" tagdir="/WEB-INF/tags/header" %>
<staticResource:staticResource></staticResource:staticResource>
<title><fmt:message key="application.title"/></title>
</head>
<body class="easyui-layout">
    <div data-options="region:'north',border:false" style="height:32px;background:#FFF;padding:0px">
	    <div class="navBox">
	     <table height="100%">
		    <tr>
			  <td><img src="${img}/home/icon0.png" /></td><td>${set.sysName}&gt;&gt; 系统管理&gt;&gt; 数据字典</td>
			</tr>
		 </table>
	    </div>
    </div>  
    <div data-options="region:'center',title:''" style="overflow-x:hidden;padding: 5px;">  
       <div id="dlg" class="easyui-dialog" closed="true"   data-options="modal:true" style="width:350px;height:auto;">
		<form id="fm" method="post" ><input type="hidden" id="dictId" name="dictId"/>
		  <table id="table3" width="99%" height="110px">
		    <tr><td height="40px" colspan="2" align="center" valign="middle"><b>数据字典</b></td>
		    <tr>
		      <td>字典名称</td><td ><input class="easyui-textbox" name="type"></td>
		    </tr>
		    <tr>
		      <td>键(key)</td><td><input class="easyui-textbox" name="code"></td>
		     </tr>
		     <tr>
		      <td>值(value)</td><td><input class="easyui-textbox" name="value"></td>
		    </tr>		
		  	<tr>
		      <td>描述</td><td><textarea rows="3" cols="3" name="description" style="width: 98%" class="easyui-textbox"></textarea></td>
		    </tr>
		    <tr align="center">
	         <td height="30" colspan="2" align="center">
	         <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="save()">确定</a>
			 &nbsp;&nbsp;
		     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
	         </td>
	        </tr>
		  </table>
		</form>
	   </div>
       <div id="toolbar" style="padding:3px">
           <div> 
	        <table>
	           <tr>
	            <td><span>字典名称:</span></td>
	            <td> <input class="easyui-validatebox" >  </td>
	            <td><a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doSearch()">搜索</a></td>
	           </tr>
	        </table>
		    </div>
	       	<div>
				<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add()">添加</a> 
				<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit()">修改</a> 
				<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteAll()">删除</a>
			</div>
	   </div>  
       <div style="float: left;width: 100%; height:auto;padding: 2px">
            <div style="float: left;width:100%;margin-top: 5px;">
				<table id="dg" >  
				</table>   
            </div>
       </div>
    </div>  
</body>

<!-- 实时数据加载 -->
<script type="text/javascript">
$(function(){
	// 获取浏览器窗口 
	var windowScreen = document.documentElement;
	var h=windowScreen.clientHeight;
	$('#dg').datagrid({  
		title:'数据字典',       
		url:"${ctx}/system/dict/list",
	    height:(h-50),  
		nowrap: true,  
		autoRowHeight: true,  
		striped: false, 
		collapsible:false,  
		fitColumns:true,
		singleSelect:true,
		pagination : true,//显示分页 ,
        toolbar:$("#toolbar"),
        idField:"dictId",
        rownumbers:true,
        columns:[
          [  
            {field:'dictId',hidden:true},
            {field:'type',title:'字典名称',width:10},
            {field:'code',title:'键(key)',width:10},
            {field:'value',title:'值(value)',width:10},
            {field:'description',title:'描述',width:20}
        ]]
    });  

});

var url;
function add(){
	$('#dlg').dialog('open').dialog('setTitle','添加数据字典信息');
	$('#fm').form('clear');
	url = '${ctx}/system/dict/save';
}
function edit(){
	var rows = $('#dg').datagrid('getSelections');
	if (rows.length != 1) {
		$.messager.alert('提示', '请选择一条记录', 'info');
	} else {
		$('#dlg').dialog('open').dialog('setTitle', '修改数据字典信息');
		$('#fm').form('load', rows[0]);
		url = '${ctx}/system/dict/update';
	}
}
function save() {
	$('#fm').form('submit', {
		url : url,
		onSubmit : function() {
			return $(this).form('validate');
		},
		success : function(response) {
			response = eval('(' + response + ')');
			$.messager.show({
				title : response.title,
				msg : response.msg,
				timeout : response.timeout,
				showType : response.showType
			});
			$('#dlg').dialog('close');
			$('#dg').datagrid('reload');
		}
	});
}
function deleteAll(){
var rows = $('#dg').datagrid('getSelections');
if(null==rows || rows.length<1){
	$.messager.alert('提示','请至少选择一条记录','info');
}else{
	$.messager.confirm('提示','确认删除选中的记录吗?',function(r){
		//获取datagrid选中行
		if (r){
			$.post('${ctx}/system/dict/deleteAll?dictId='+rows[0].dictId,function(response){
				$.messager.show({
					title:response.title,
					msg:response.msg,
					timeout:response.timeout,
					showType:response.showType
				});
				$('#dlg').dialog('close');
				$('#dg').datagrid('reload');
			},'json');
		}
	});
}
}
//search
function doSearch(){
	$('#dg').datagrid('load', {    
	}); 
}

</script>
</html>